﻿/*
 *	value: format dau vao phai la dd/mm/yyyy
 *  format: chuoi format dau ra la: mm/dd/yyyy, yyyy/mm/dd
 */

function formatDate (value, format) {
    var daysInMonth = DaysArray(12);
    var pos1 = value.indexOf(dtCh);
    var pos2 = value.indexOf(dtCh, pos1 + 1);
    var strDay = value.substring(0, pos1);
    var strMonth = value.substring(pos1 + 1, pos2);
    var strYear = value.substring(pos2 + 1);
    strYr = strYear;
    if (strDay.charAt(0) == "0" && strDay.length > 1)
        strDay = strDay.substring(1);
    if (strMonth.charAt(0) == "0" && strMonth.length > 1)
        strMonth = strMonth.substring(1)
    for (var i = 1; i <= 3; i++) {
        if (strYr.charAt(0) == "0" && strYr.length > 1)
            strYr = strYr.substring(1)
    }
    switch (format) {
        case "dd/mm/yyyy":
            return strDay + "/" + strMonth + "/" + strYear;
            break;
        case "mm/dd/yyyy":
            return strMonth + "/" + strDay + "/" + strYear;
            break;
        case "yyyy/mm/dd":
            return strYear + "/" + strMonth + "/" + strDay;
            break;
    }
}